package helper

import (
	"github.com/labstack/echo/v4"
	"math/rand"
	"strconv"
	"time"
)

func ParseUintParam(c echo.Context, name string) (uint, error) {
	param := c.Param(name)
	id64, err := strconv.ParseUint(param, 10, 32)
	if err != nil {
		return 0, err
	}
	return uint(id64), nil
}
func ParseUintQueryParam(c echo.Context, name string) (uint, error) {
	param := c.QueryParam(name)
	id64, err := strconv.ParseUint(param, 10, 32)
	if err != nil {
		return 0, err
	}
	return uint(id64), nil
}

func Ptr[T any](val T) *T {
	return &val
}

func RandomDigits(n uint) string {
	if n <= 0 {
		return ""
	}

	rand.Seed(time.Now().UnixNano())

	digits := "0123456789"
	result := make([]byte, n)

	for i := range result {
		result[i] = digits[rand.Intn(len(digits))]
	}

	return string(result)
}

//verificationCode := GenerateRandomDigits(4)
